package service.iml;

import base.StatusCode;
import dao.iml.CourseContentDao;
import dao.iml.CourseContentDaoImpl;
import dao.iml.CourseDao;
import dao.iml.CourseDaoImpl;
import pojo.Course;
import pojo.Course_Lesson;
import pojo.Course_Section;

import java.util.List;

public class ServiceDaoImpl implements ServiceDao {
    CourseDao courseDao = new CourseDaoImpl();
    CourseContentDao ccd = new CourseContentDaoImpl();
    @Override
    public List<Course> findCourseList() {
        List<Course> byfindCourseList = courseDao.findCourseList();
        return byfindCourseList;
    }

    @Override
    public List<Course> findByCourseNameAndStatus(String course_name, String status) {
        List<Course> byCourseNameAndStatus = courseDao.findByCourseNameAndStatus(course_name, status);
        return byCourseNameAndStatus;
    }

    @Override
    public Course findCourseById(int id) {
        Course course = courseDao.findCourseById(id);
        return course;
    }

    @Override
    public String courseSalesInfo(Course course) {
        int row = courseDao.courseSalesInfo(course);
        if (row > 0){
            String success = StatusCode.SUCCESS.toString();
            return success;
        }else {
            String fail = StatusCode.FAIL.toString();
            return fail;
        }
    }

    @Override
    public String updateCourse(Course course) {
        int i = courseDao.updateCourse(course);
        if (i > 0){
            String success = StatusCode.SUCCESS.toString();
            return success;
        }else {
            String fail = StatusCode.FAIL.toString();
            return fail;
        }
    }

    @Override
    public String updateCourseStatus(int id, int status) {
        return courseDao.updateCourseStatus(id,status);
    }

    @Override
    public List<Course_Section> findSectionCourseId(int courseId) {
        List<Course_Section> sectionAndLessonByCourseId = ccd.findSectionCourseId(courseId);
        return sectionAndLessonByCourseId;
    }

    @Override
    public String saveSection(Course_Section course_section) {
        int i = ccd.saveSection(course_section);
        if (i > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSectionStatus(Course_Section course_section) {
        int row = ccd.updateSectionStatus(course_section);
        if (row > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String saveLesson(Course_Lesson course_lesson) {
        int row = ccd.saveLesson(course_lesson);
        if (row > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }

    }

    @Override
    public String updateLesson(Course_Lesson course_lesson) {
        int row = ccd.updateLess(course_lesson);
        if (row > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }


}
